﻿using System;
using System.Collections.Generic;
using System.Text;
using CFSystem.JXC.IDAL;
using CFSystem.JXC.Model;
using System.Data;
using System.Data.OleDb;
using DBUtility;

namespace CFSystem.JXC.AccessDAL
{
    public class Brand : IBrand
    {

        public Brand()
        { }

        /// <summary>
        /// Method to get all BrandInfo
        /// </summary>		
        /// <returns>Interface to Model Collection Generic of Brands</returns>
        public IList<BrandInfo> GetBrands()
        {

            string sqlSelect = "SELECT * from tb_Brand";

            OleDbDataReader dr = AccessHelper.ExecuteReader(AccessHelper.ConnectionString, CommandType.Text, sqlSelect);

            IList<BrandInfo> brandItems = new List<BrandInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    BrandInfo bi = new BrandInfo(Convert.ToInt32(dr[0].ToString()),
                                                                       Convert.ToString(dr[1].ToString()),
                                                                       Convert.ToString(dr[2]));
                    brandItems.Add(bi);
                }
                dr.Close();
            }
            return brandItems;
        }

        /// <summary>
        /// Get information on a specific Brand
        /// </summary>
        /// <param name="categoryId">Unique identifier for a Brand</param>
        /// <returns>Business Entity representing an Brand</returns>
        public BrandInfo GetBrand(string BrandID)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="BrandName"></param>
        public void InsertBrand(string BrandName)
        {
            string sqlInsert = "insert into [tb_Brand]([Name],[memo]) values('" + BrandName + "','test')";

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlInsert);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="BrandID"></param>
        public void DelBrandByID(int BrandID)
        {
            string sqlDel = "delete from [tb_Brand] where [BrandID]=" + BrandID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlDel);

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="BrandID"></param>
        /// <param name="updValue"></param>
        public void UpdateBrandByID(int BrandID, string updValue)
        {
            string sqlUpd = "update [tb_Brand] set [Name] ='" + updValue + "'" + " where [BrandID]=" + BrandID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlUpd);

        }
    }
}
